add_rules("mode.debug","mode.release")

option("configure")
    set_default(true)
    set_showmenu(true)
option("demo")
    set_default(true)
    set_showmenu(true)
option("demo_path")
    set_showmenu(true)


includes("src/xmake.lua")
-- if has_config("configure") 
-- then
--     target("configure1")
--         on_load(function ( target )
--             import("core.project.config")
--             str=path.absolute(config.buildir())
--             str1=string.gsub(str,"\\","/")
--             str2="#define MESH_VIEWER_PATH \""..str1.."/..\""
--             io.writefile("include/config.h",str2)
--         end)
-- end


if has_config("demo") 
then
    target("main")
        set_targetdir("bin")
        set_kind("binary")
        add_files("$(demo_path)/*.cpp","$(demo_path)/*.c","src/*.cpp")

        add_includedirs("include","$(demo_path)/include","thirdpart/cstructures/include",
            "thirdpart/glad/include","thirdpart/glfw/include","thirdpart/freetype/include","thirdpart/lbmath/include",
            "thirdpart/viewer/include","thirdpart/libcell/include","thirdpart/URDF_Parser/include","thirdpart/eigen3")
        add_includedirs("thirdpart/imgui/include","thirdpart")
        --add_links("viewer","cstructures")
        add_linkdirs("lib","temp_libs")
 
        --add_deps("viewer")
        -- add_links("avformat","avcodec","avutil","swscale","swresample","m")
        if is_plat("linux") then
            add_syslinks( "viewer","libcell","lbmath","cstructures","glfw3","freetype", "GL", "Xrandr", "Xi", "X11",
                "Xxf86vm", "pthread", "Xinerama", "Xcursor","dl", "png","bz2","z","harfbuzz")
            add_ldflags("-no-pie ")
            add_cflags("-O3")
            add_cxflags("-O3 ")
            add_cxxflags("-O3")
        elseif is_plat("mingw") then
            print("mingw")
            add_syslinks("viewer","libcell","lbmath","cstructures","glfw3","opengl32","freetype","gdi32","comdlg32","advapi32","Z")
            add_ldflags("-no-pie ") 
            add_cxflags("-O3")
            add_cxxflags("-O3")
        else 
            print("not mingw")
            add_cxflags("/MD /Od /std:c++17")
            add_cxxflags("/MD /Od /std:c++17")

            add_syslinks("viewer","libcell","lbmath","cstructures", "opengl32","glfw3","freetype","kernel32","user32"
                ,"gdi32","comdlg32","advapi32","shell32" )
        end
     --    on_load(function (target)
     --    	target:add(find_packages("freetype2", "glfw3"))
    	-- end) 
end 
